package com.tuton.javanet.chapter02;

import java.io.IOException;
import java.net.Socket;

public class PortScaner {

	
	
	public static void main(String[] args) {
		String host = "localhost";
		if(args.length > 0) {
			host = args[0];
		}
		new PortScaner().ScanPort(host);

	}

	private static void ScanPort(String host) {
		Socket socket = null;
		for(int i =8070; i < 8090; i++) {
			try{
				int port = i;
				socket = new Socket(host,port);
				System.out.println("Found a servcie on" + socket.getPort());
			}catch(IOException ex) {
				System.out.println("Can not find a server ");
			}finally {
				try {
					if(socket != null) {
						socket.close();
					}
				} catch(IOException ex) {
					ex.printStackTrace();
				}
			}
		}
		
	}

}


